# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'jsbc.ui'
#
# Created: Fri Jan 07 19:51:51 2011
#      by: PyQt4 UI code generator 4.8.2
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui
import threading
import os
#import preprocessing.sessidentify   //sealala部分

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    _fromUtf8 = lambda s: s

class Ui_Dialog(object):
    def setupUi(self, Dialog):
        Dialog.setObjectName(_fromUtf8("Dialog"))
        Dialog.resize(495, 245)
        self.pushButton_2 = QtGui.QPushButton(Dialog)
        self.pushButton_2.setGeometry(QtCore.QRect(50, 30, 75, 23))
        self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
        self.widget = QtGui.QWidget(Dialog)
        self.widget.setGeometry(QtCore.QRect(50, 90, 291, 25))
        self.widget.setObjectName(_fromUtf8("widget"))
        self.gridLayout = QtGui.QGridLayout(self.widget)
        self.gridLayout.setMargin(0)
        self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
        self.pushButton = QtGui.QPushButton(self.widget)
        self.pushButton.setObjectName(_fromUtf8("pushButton"))
        self.gridLayout.addWidget(self.pushButton, 0, 0, 1, 1)
        self.pushButton_3 = QtGui.QPushButton(self.widget)
        self.pushButton_3.setObjectName(_fromUtf8("pushButton_3"))
        self.gridLayout.addWidget(self.pushButton_3, 0, 1, 1, 1)
        self.pushButton_4 = QtGui.QPushButton(self.widget)
        self.pushButton_4.setObjectName(_fromUtf8("pushButton_4"))
        self.gridLayout.addWidget(self.pushButton_4, 0, 2, 1, 1)
        self.widget1 = QtGui.QWidget(Dialog)
        self.widget1.setGeometry(QtCore.QRect(50, 160, 192, 25))
        self.widget1.setObjectName(_fromUtf8("widget1"))
        self.gridLayout_2 = QtGui.QGridLayout(self.widget1)
        self.gridLayout_2.setMargin(0)
        self.gridLayout_2.setObjectName(_fromUtf8("gridLayout_2"))
        self.pushButton_5 = QtGui.QPushButton(self.widget1)
        self.pushButton_5.setObjectName(_fromUtf8("pushButton_5"))
        self.gridLayout_2.addWidget(self.pushButton_5, 0, 0, 1, 1)
        self.pushButton_6 = QtGui.QPushButton(self.widget1)
        self.pushButton_6.setObjectName(_fromUtf8("pushButton_6"))
        self.gridLayout_2.addWidget(self.pushButton_6, 0, 1, 1, 1)

        self.retranslateUi(Dialog)
        QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL(_fromUtf8("clicked()")), self.removeRobot)
        QtCore.QObject.connect(self.pushButton_3, QtCore.SIGNAL(_fromUtf8("clicked()")), self.cleanLog)
        QtCore.QObject.connect(self.pushButton_4, QtCore.SIGNAL(_fromUtf8("clicked()")), self.genSQL)
        QtCore.QObject.connect(self.pushButton_5, QtCore.SIGNAL(_fromUtf8("clicked()")), self.identifySession)
        QtCore.QObject.connect(self.pushButton_2, QtCore.SIGNAL(_fromUtf8("clicked()")), self.configure)
        QtCore.QObject.connect(self.pushButton_6, QtCore.SIGNAL(_fromUtf8("clicked()")), self.urlCategory)
        QtCore.QMetaObject.connectSlotsByName(Dialog)
        Dialog.setTabOrder(self.pushButton_2, self.pushButton)
        Dialog.setTabOrder(self.pushButton, self.pushButton_3)
        Dialog.setTabOrder(self.pushButton_3, self.pushButton_4)
        Dialog.setTabOrder(self.pushButton_4, self.pushButton_5)

    def retranslateUi(self, Dialog):
        Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "Dialog", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton_2.setText(QtGui.QApplication.translate("Dialog", "configure", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton.setText(QtGui.QApplication.translate("Dialog", "Remove Robot", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton_3.setText(QtGui.QApplication.translate("Dialog", "Clean Log", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton_4.setText(QtGui.QApplication.translate("Dialog", "Generate Sql Source", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton_5.setText(QtGui.QApplication.translate("Dialog", "Session Identify", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton_6.setText(QtGui.QApplication.translate("Dialog", "URL Category", None, QtGui.QApplication.UnicodeUTF8))

    def removeRobot(Dialog):
        parseLog('r')
#        path = os.path.abspath('')
#        path = path[:-2]+'clean\\main.py'
#        th = threading.Thread(target=os.system("python "+path+" -a r")) ; 
#        th.start()
        print("worker successfully!")
       
    def cleanLog(Dialog):
        parseLog('c')
        print("clean log")
        
    def genSQL(Dialog):
        parseLog('g')
        print("get sql")
    
    def identifySession(Dialog):
        path = os.path.abspath('')
        path = path[:-2]+'preprocessing\\loadlog.py'
        th = threading.Thread(target=os.system("python "+path)) ; 
        th.start()
        print("identify session")

    def urlCategory(Dialog):
        path = os.path.abspath('')
        path = path[:-2]+'prepare\\url2type.pl'
        th = threading.Thread(target=os.system("perl "+path)) ; 
        th.start()
        print('url category')
        
    def configure(Dialog):
        path = os.path.abspath('')
        path = path[:-2]+'\\config.py'
        th = threading.Thread(target=os.system("edit "+path)) ; 
        th.start()
        print('configuration complete!')

def parseLog(str):
        path = os.path.abspath('')
        path = path[:-2]+'clean\\main.py'  
        if str.find("r") >= 0:
            th1 = threading.Thread(target=os.system("python "+path+" -a r")) ; 
            th1.start()
            
        if str.find("c") >= 0:
            th2 = threading.Thread(target=os.system("python "+path+" -a c")) ; 
            th2.start()
        if str.find("g") >= 0:
            th3 = threading.Thread(target=os.system("python "+path+" -a g")) ; 
            th3.start()
        